/**
 * The function for decimal's add, subtract, multiplication, division. Not get the float result.
 * And add the function to Number's prototype, so you can use it as:
 * var result = dcmAdd(0.2,0.1); //or var result = (0.2).add(0.1);
 * */
function floatAdd(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	n = Math.max(r1, r2);
	m = Math.pow(10, n);
	return ((arg1 * m + arg2 * m) / m).toFixed(n);
}

function floatSbt(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	n = Math.max(r1, r2);
	m = Math.pow(10, n);
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

function floatMul(arg1, arg2) {
	var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
	try {
		m += s1.split(".")[1].length
	} catch (e) {
	}
	try {
		m += s2.split(".")[1].length
	} catch (e) {
	}
	return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}

function floatDiv(arg1, arg2) {
	var t1 = 0, t2 = 0, r1, r2;
	try {
		t1 = arg1.toString().split(".")[1].length
	} catch (e) {
	}
	try {
		t2 = arg2.toString().split(".")[1].length
	} catch (e) {
	}
	r1 = Number(arg1.toString().replace(".", ""));
	r2 = Number(arg2.toString().replace(".", ""));
	return (r1 / r2) * Math.pow(10, t2 - t1);
};

//对数字进行格式化,保证precision位
function point(number,precision)
{
  if(isNaN(number))
    number = 0;
  var result = number.toString();
  if(result.indexOf(".")==-1)
    result = result + ".";

  result = result + newString("0",precision);
  result = result.substring(0,precision + result.indexOf(".") + 1);
  return result;
}

//对数字四舍五入
//数值,精度
function round(number,precision)
{
  if(isNaN(number))
    number = 0;
  var prec = Math.pow(10,precision);
  var result = Math.round( number * prec) ;
  result = result/prec;
  return result;
}

/**
 * 将给定字符串复制ｎ遍
 * @param intLength 字符串长度
 * @return 字符串
 */
function newString(iString, iTimes)
{
  var str = "";
  for (var i = 0 ; i < iTimes; i++)
     str = str + iString;
  return str;
} 


Number.prototype.succ = function () {
	return this + 1;
},

	Number.prototype.add = function (arg) {
		return floatAdd(this, arg);
	},

	Number.prototype.sub = function (arg) {
		return floatSbt(this, arg);
	},

	Number.prototype.mul = function (arg) {
		return floatMul(this, arg);
	},

	Number.prototype.div = function (arg) {
		return floatDiv(this, arg);
	}
Number.prototype.succ = function () {
	return this + 1;
};

String.prototype.add = function (arg) {
	return floatAdd(this, arg);
};

String.prototype.sub = function (arg) {
	return floatSbt(this, arg);
};

String.prototype.mul = function (arg) {
	return floatMul(this, arg);
};

String.prototype.div = function (arg) {
	return floatDiv(this, arg);
};